"""
 Coatl 2008 GPLv3
 Colectivo MonoNeurona.org
"""
from django.shortcuts import render_to_response
from django.db import models
from django.core.mail import send_mail
from django.http import Http404
from models import News
from datetime import datetime
import os, unittest


def latest_posts(request):
    post_list = News.objects.order_by('date')[:10]
    return render_to_response('blog/view.html', {'post_list':post_list})

def display(request):
    news_list = News.objects.filter(status=1).order_by("-id")[:10]
    #__newMail()
    return render_to_response('news/display.html', {'news_list':news_list})

def view(request, slug):
    #exit(raise Exception(repr(offset)))
    try:
        new_slug = slug.replace(' ', '_')
        new = News.objects.get(slug=new_slug)
        mydict = {'new':new}
       
    except News.DoesNotExist:
        raise Http404
    return render_to_response('news/view.html', mydict)

def __newMail():
    send_mail('This is the subject', 'Gracias! for subscribing to alerts', 'support@gmail.com', ['mmontoya@gmail.com'])
    return True

class Feed(models.Model):
    """
    storage for "what's new?" feeds
    """
    site = models.PositiveSmallIntegerField(unique=True) # site id
    html = models.TextField() # rendered html
    rss = models.CharField(max_length=4) # rss
